package com.question.controller.user;

import com.question.pojo.result.Result;
import com.question.pojo.vo.CommentLikeVO;
import com.question.service.CommentLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users/commentlike")
@Slf4j
@Api(tags = "评论点赞相关接口")
public class CommentLikeController {

    @Autowired
    private CommentLikeService commentLikeService;

    /**
     * 评论添加取消点赞
     * @param commentId
     * @return
     */
    @PostMapping("/{commentId}")
    @ApiOperation("评论添加取消点赞")
    public Result likeOrUnlike(@PathVariable Integer commentId) {
        log.info("评论添加取消点赞:{}", commentId);
        commentLikeService.likeOrUnlikeComment(commentId);
        return Result.success();
    }

    /**
     * 获取评论点赞数
     * @param questionId
     * @return
     */
    @GetMapping("/count/{questionId}")
    @ApiOperation("获取评论点赞数")
    public Result<List<CommentLikeVO>> getCount(@PathVariable Integer questionId){
        log.info("获取评论点赞数:{}", questionId);
        List<CommentLikeVO> commentLikeVOList = commentLikeService.getCommentLikeCount(questionId);
        return Result.success(commentLikeVOList);
    }

    /**
     * 获取当前用户点赞评论列表
     * @param questionId
     * @return
     */
    @GetMapping("/list/{questionId}")
    @ApiOperation("获取当前用户点赞评论列表")
    public Result<List<Integer>> get(@PathVariable Integer questionId) {
        List<Integer> commentIdList = commentLikeService.getCommentLikeListByUserId(questionId);
        return Result.success(commentIdList);
    }
}
